package cn.iocoder.yudao.module.agent.controller.app.brokerageclue;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.agent.controller.admin.brokerageclue.vo.AgentBrokerageClueCreateReqVO;
import cn.iocoder.yudao.module.agent.controller.admin.brokerageclue.vo.AgentBrokerageCluePageReqVO;
import cn.iocoder.yudao.module.agent.controller.admin.brokerageclue.vo.AgentBrokerageClueRespVO;
import cn.iocoder.yudao.module.agent.convert.brokerageclue.AgentBrokerageClueConvert;
import cn.iocoder.yudao.module.agent.dal.dataobject.brokerageclue.AgentBrokerageClueDO;
import cn.iocoder.yudao.module.agent.service.brokerageclue.AgentBrokerageClueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 分销线索")
@RestController
@RequestMapping("/agent/brokerage-clue")
@Validated
public class AppAgentBrokerageClueController {
    @Resource
    private AgentBrokerageClueService brokerageClueService;


    @PostMapping("/create")
    @Operation(summary = "创建代理人分销用户线索")
    public CommonResult<Long> createBrokerageClue(@Valid @RequestBody AgentBrokerageClueCreateReqVO createReqVO) {
        return success(brokerageClueService.createBrokerageClue(createReqVO));
    }

    @GetMapping("/page")
    @Operation(summary = "获得代理人分销用户线索分页")
    public CommonResult<PageResult<AgentBrokerageClueRespVO>> getBrokerageCluePage(@Valid AgentBrokerageCluePageReqVO pageVO) {
        PageResult<AgentBrokerageClueDO> pageResult = brokerageClueService.getBrokerageCluePage(pageVO);
        return success(AgentBrokerageClueConvert.INSTANCE.convertPage(pageResult));
    }
}
